import time

from selenium.webdriver.common.by import By

from base.page_base import BasePage


class LimitAffirm(BasePage):
    loanman=(By.XPATH,'/html/body/div[1]/div[2]/ul/li[2]/a')
    limit_management=(By.XPATH,'//*[@id="sidebar"]/ul/li[5]/a/span')
    amount_verification=(By.XPATH,'//*[@id="sidebar"]/ul/li[5]/ul/li[2]/a')
    new_frome=(By.ID, "iframe_box")
    username=(By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[1]/div/input')
    search=(By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[3]/input')

    new_label=(By.XPATH,'/html/body/div[2]/div[3]/table/tbody/tr[1]/td[1]')
    new_button=(By.XPATH,'/html/body/div[2]/div[2]/ul/li[1]/a/span')
    new_rome=(By.XPATH, "/html/body/div[5]/div[1]/iframe")
    audit_button=(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[5]/td[2]/div/label[1]/span')
    remark=(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[6]/td[2]/div/textarea')
    verification=(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[7]/td[2]/div/ul/li[1]/input')
    consent=(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[8]/td[2]/input[1]')
    result=(By.XPATH,'/html/body/div[2]/div[3]/table/tbody/tr[1]/td[1]/span')
    xiala=(By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[2]/div/select/option[2]')
    audit=(By.XPATH,'/html/body/div[2]/div/div[1]/ul/li[5]/ul/li[3]/a')
    state=(By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[2]/div/select')

    pass_text=(By.XPATH,'/html/body/div[2]/div[3]/table/tbody/tr[1]/td[7]/span')
    search_button=(By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[4]/input')
    def click_loanman(self):
        self.base_click(self.loanman)
    def click_limit(self):
        self.base_click(self.limit_management)
    def click_amount(self):
        self.base_click(self.amount_verification)

    def click_new_frome(self):
        self.base_switch_frame(self.new_frome)
    def input_username(self,username):
        self.base_input(self.username,username)
    def click_search(self):
        self.base_click(self.search)

    def click_new_label(self):
        self.base_click(self.new_label)
    def click_new_button(self):
        self.base_click(self.new_button)
    def cut_new_frome(self):
        self.base_switch_frame(self.new_rome)
    def click_audit_button(self):
        self.base_click(self.audit_button)
    def input_remark(self,remark='这是一个测试账号，允许审核通过'):
        self.base_input(self.remark,remark)

    def input_verification(self,ver='8888'):
        self.base_input(self.verification,ver)
    def click_consent(self):
        self.base_click(self.consent)
    def click_app_rec(self,phone,status="通过"):
        self.base_default_frame()
        self.base_click(self.audit)
        self.base_switch_frame(self.new_frome)
        self.base_input(self.username, phone)
        self.base_select_list(self.state,status)
        self.base_click(self.search_button)

    def get_result_text(self):
        time.sleep(1)
        return self.fd_element(self.pass_text).text



    def audit_business(self,username='13810012011'):
        """业务流程"""
        self.click_loanman()
        self.click_limit()
        self.click_amount()
        self.click_new_frome()
        self.input_username(username)
        self.click_search()
        time.sleep(1)
        self.click_new_label()
        self.click_new_button()
        self.cut_new_frome()
        self.click_audit_button()
        self.input_remark()
        self.input_verification()
        self.click_consent()
